import { userLogin } from '@/api/user'
import { defineStore } from 'pinia'
import { ref } from 'vue'

type UserInfo = {
    username: string;
    roles: string[];
    accessToken: string;
}
export const useUserStore = defineStore('user',()=> {
    const userInfo = ref<UserInfo>({
        username: '',
        roles: [],
        accessToken: '',
    })
    const storeUserLogin = async (data?: { username: string; password: string }) => { 
        const res = await userLogin(data);
        userInfo.value = res;
        return res;
    }
    return { userInfo, storeUserLogin }
}, {
    persist: {
        storage:localStorage,
        key: 'userInfo'
    }
})
